package com.stox.ui.javafx.charting.widget;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.ComboBox;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stox.ui.javafx.charting.model.enumeration.Span;
import com.stox.ui.javafx.charting.model.enumeration.SpanType;
import com.stox.ui.javafx.core.widget.wrapper.ToolBar.ToolBarChild;

@Component
public class SpanTypeComboBox extends ComboBox<SpanType> implements ToolBarChild, InitializingBean{

	@Autowired
	private SpanComboBox spanComboBox;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		spanComboBox.valueProperty().addListener(new ChangeListener<Span>() {
            @Override public void changed(ObservableValue<? extends Span> ov, Span t, Span span) {
            	getItems().clear();
            	getItems().addAll(span.getSpanTypes());
            	getSelectionModel().select(0);
            }    
        });
		spanComboBox.setValue(Span.YEAR_1);
	}
	
	@Override
	public int getOrder() {
		return 1;
	}
	
}
